from itertools import product
from typing import Union, Dict

from flask import Flask,request
from flask import render_template
# 调用自定义模块中的函数
from reserch import reserch4letters
from food_system import system

# Flask:中央登记中心
app = Flask(__name__)

# 【Flask】(https://dormousehole.readthedocs.io/en/latest/quickstart.html#id10)
# 【HTMl】(https://www.w3school.com.cn/html/index.asp)
# 【jinja2】(https://palletsprojects.com/p/jinja/)

# 1. 路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
# 1.1 url: 相对于：http://127.0.0.1：5000的相对路径
# 1.2 methods:【GET】【POST】
# 2. 视图函数：
# 2.1 函数过程决定了你操作的方法（实现的功能），例如 if elif else for while ...
# 2.2 return：返回数据内容，text文本，HTML文件（模板渲染），JSON文件等

# 【GET】
@app.route('/',methods=['GET'])
def home():
    return render_template('home.html')

@app.route('/food',methods=['GET'])
def food():
    return render_template('food.html')

# @app.route('/dish',methods=['GET'])
# def word():
#     return render_template('dish.html')

# 【POST】实现用户输入，点击提交，将数据提交到 /result
@app.route('/result_food',methods=['POST','GET'])
def result_food():
    py_kind = request.form['food']
    result = food_system.system(py_kind)
    return render_template('result_food.html',
                           food = result)
@app.route('/result_word',methods=['POST','GET'])
# def result_word():
#     py_word = request.form['word']
#     py_vowels = request.form['vowels']
#     py_found = reserch4letters(py_vowels,py_word)
#     return render_template('result_word.html',
#                            found = py_found)

if __name__ == '__main__':
    app.run(host='127.0.0.1',port=5000,debug=True)
